<link href="<?=site_url()?>css/jquery-ui-1.8.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?=site_url()?>js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?=site_url()?>js/jquery-ui-1.8.custom.min.js"></script>
<script type="text/javascript" src="<?=site_url()?>js/jquery.ui.datepicker-th.js"></script>
<style type="text/css">
.ui-datepicker {
	width: 13em;
}
.ui-widget {
	font-size: 1em;
}
</style>
<script language="javascript">
	$().ready(function() {
		$("#txtBirthday").datepicker({
			showOn: 'button',
			buttonImage: '<?=site_url()?>images/calbtn.gif',
			buttonImageOnly: true,
			changeMonth: true,
			changeYear: true,
			yearRange: 'c-40:c'
		});		
	});

	function handleTitle(val) {
		if(val.value == "อื่นๆ") {
			document.getElementById("txtTitleOther").readOnly = false;
			document.getElementById("txtTitleOther").className = "";
			document.getElementById("txtTitleOther").focus();
		} else {
			document.getElementById("txtTitleOther").readonly = true;
			document.getElementById("txtTitleOther").className = "textReadonly";
			document.getElementById("txtTitleOther").value = "";
		}
	}
	function handleCurrentClass(obj) {
		if(obj.value == "สูงกว่า ป. ตรี (โปรดระบุ)") {		
			document.getElementById('txtCurrentClassOther').style.visibility="visible";
			document.getElementById('txtCurrentClassOther').focus();
		} else {
			document.getElementById('txtCurrentClassOther').style.visibility="hidden";
			document.getElementById('txtCurrentClassOther').value = '';
		}
	}
	
	function handleCouse(obj) {
		if(obj.value == "อื่นๆ (โปรดระบุ)") {		
			document.getElementById('txtCourseOther').style.visibility="visible";
			document.getElementById('txtCourseOther').focus();
		} else {
			document.getElementById('txtCourseOther').style.visibility="hidden";
			document.getElementById('txtCourseOther').value = '';
		}
	}
	
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}

	function checkImageExt(obj) {
		var t = obj.value;
		var txt = obj.value.substring(obj.value.lastIndexOf(".")+1).toLowerCase();
		if(!(txt == "jpg" || txt == "jpeg" || txt == "gif" || txt == "png")) {
			alert("ไฟล์รูปภาพที่แนบมาไม่ถูกต้อง " + t + "\nกรุณาเลือกไฟล์ใหม่");	
			u = document.getElementById('uploader');
			u.innerHTML=' <input name="txtStudentImg" id="txtStudentImg" type="file" style="width:500px;" onchange="checkImageExt(this);" /> ';
		}
	}

	function validateForm() {
		if(trim(document.getElementById('txtFirstName').value).length == 0) {
			document.getElementById('txtFirstName').focus();
			alert("กรุณาใส่ชื่อ");
			return false;		
		} else if(trim(document.getElementById('txtLastName').value).length == 0) {
			document.getElementById('txtLastName').focus();
			alert("กรุณาใส่นามสกุล");
			return false;		
		} 
		var cc = document.getElementsByName('chkSchool[]'); 
	    for (var i = 0; i < cc.length; i++)  {
	        if(cc[i].checked == true)
		        return true; 
	    }
	    alert('กรุณาเลือกโรงเรียนในสังกัด อย่างน้อย 1 โรงเรียน');
	    return false;
	}
</script>
<div id="mainContent">
<?=form_open_multipart('StudentInfo/upload', array('onsubmit' => 'return validateForm();'));?>
<input type="hidden" name="status" id="status" value="<?=$form_status?>" />
<input type="hidden" name="studentId" id="studentId"  <?php if(isset($student_id)) echo ' value="'.$student_id.'"';?>/>
<table width="1000px" border="0" cellspacing="2px" cellpadding="0" align="center" >
	<tr align="center">
    	<td>
    		<?php
    			if(isset($student_id)) {
    				echo ' <h2><b><font color="blue">'. $first_name .' ' . $last_name .'</font></h2> ';
					echo ' [<a href="'.site_url().'StudentInfo/detail/'.$student_id.'" >ประวัติส่วนตัว</a>] | 
						   [<a href="'.site_url().'StudentInfo/detailContractInfo/'.$student_id.'" >ข้อมูลการติดต่อ</a>]| 
						   [<a href="'.site_url().'StudentInfo/detailBooking/'.$student_id.'" >ข้อมูลการจอง</a>]   | 
						   [<a href="'.site_url().'StudentInfo/detailStudied/'.$student_id.'" >ประวัติกับสถาบัน</a>] ';    				
    			} else {
    				echo " [ประวัติ ส่วนตัว] | [ข้อมูล การติดต่อ]| [ข้อมูล การจอง] | [ประวัติ กับสถาบัน] ";
    			}
    		?>	
    	</td>
    </tr>
    <tr align="center">
    	<td>
        	<table width="900px">
            	<tr>
                	<td align="left">
                    	วันที่ลงข้อมูลครั้งแรก <?php if($form_status == 'add') echo "-"; else echo $create_date; ?> 
                    	โดย <?php if($form_status == 'add') echo "-"; else echo $create_by; ?>            	
                    </td>
                    <td align="right">
                    	วันที่ลงข้อมูลครั้งล่าสุด <?php if($form_status == 'add' || $update_date == null) echo "-"; else echo $update_date; ?> 
                    	โดย <?php if($form_status == 'add' || $update_by == null) echo "-"; else echo $update_by; ?>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
	<tr style="height:10px;">
    	<td></td>
    </tr>
	<tr>
		<td align="center">
          <fieldset style="width: 950px;">
          <legend>ข้อมูลส่วนตัว</legend>
          	<?php if($form_status != 'notPermit') {?>
                <table width="950px" border="0" cellspacing="2px" cellpadding="0">
                  <col width="150px" />
                  <col width="*" />
                  <col width="150px" />
                  <tr>
                    <td align="right"><label>คำนำหน้าชื่อ</label></td>
                    <td align="left"><input name="radTitle" type="radio" id="radTitle1" value="นาย" <?php if($form_status == 'add' || (isset($title) && $title == 'นาย')) echo 'checked="checked"'; ?> onclick="handleTitle(this);" />
                      นาย
                      <input type="radio" name="radTitle" id="radTitle2" value="นาง" <?php if($form_status != 'add' && (isset($title) && $title == 'นาง')) echo 'checked="checked"'; ?> onclick="handleTitle(this);"/>
                      นาง
                      <input type="radio" name="radTitle" id="radTitle3" value="นางสาว" <?php if($form_status != 'add' && (isset($title) && $title == 'นางสาว')) echo 'checked="checked"'; ?> onclick="handleTitle(this);"/>
                      นางสาว
                      <input type="radio" name="radTitle" id="radTitle4" value="ด.ช." <?php if($form_status != 'add' && (isset($title) && $title == 'ด.ช.')) echo 'checked="checked"'; ?> onclick="handleTitle(this);"/>
                      ด.ช. 
                      <input type="radio" name="radTitle" id="radTitle5" value="ด.ญ." <?php if($form_status != 'add' && (isset($title) && $title == 'ด.ญ.')) echo 'checked="checked"'; ?> onclick="handleTitle(this);"/>
                      ด.ญ.
                      <input type="radio" name="radTitle" id="radTitle6" value="อื่นๆ" <?php if($form_status == 'add' || (isset($title) && ($title == 'นาย' || $title == 'นาง' || $title == 'นางสาว' || $title == 'ด.ช.' || $title == 'ด.ญ.'))) echo ''; else echo 'checked="checked"';?> onclick="handleTitle(this);"/>
                      อื่นๆ
                      <input name="txtTitleOther" type="text" id="txtTitleOther" <?php if($form_status == 'add' || (isset($title) && ($title == 'นาย' || $title == 'นาง' || $title == 'นางสาว' || $title == 'ด.ช.' || $title == 'ด.ญ.'))) echo 'readonly="readonly" class="textReadonly"'; else echo ' value="'.$title.'"';?>  />
                    </td>
                    <td rowspan="11"><img src="<?=site_url()?>data-image/student/<?php if($form_status == 'add' || $student_image == null) echo 'noImg.jpg'; else echo $student_image; ?>" width="150px" /></td>
                  </tr>
                  <tr>
                    <td align="right"><label>ชื่อ</label></td>
                    <td align="left"><input name="txtFirstName" id="txtFirstName" type="text" maxlength="45" value="<?php if($form_status != 'add' && (isset($first_name))) echo $first_name; ?>" />
                        <span class="require">*</span>
                        <label> นามสกุล </label>
                        <input name="txtLastName" id="txtLastName" type="text" maxlength="45" value="<?php if($form_status != 'add' && (isset($last_name))) echo $last_name; ?>"/>
                      <span class="require">*</span> <label> ชื่อเล่น </label>
                        <input name="txtNickName" id="txtNickName" type="text" maxlength="45" value="<?php if($form_status != 'add' && (isset($nick_name))) echo $nick_name; ?>"/>
                      </td>
                  </tr>
                  <tr>
                    <td align="right"><label>วัน เดือน ปีเกิด</label></td>
                    <td align="left"><input name="txtBirthday" type="text" class="textReadonly" id="txtBirthday"  readonly="readonly" value="<?php if($form_status != 'add' && (isset($birthday))) echo $birthday; ?>"/>
                         <label>ชั้น</label>                     
                        <select name="txtCurrentClass" id="txtCurrentClass" onchange="handleCurrentClass(this);">
                          <option value="ต่ำกว่า อ. 1" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ต่ำกว่า อ. 1') echo 'selected="selected"';?>>ต่ำกว่า อ. 1</option>
                          <option value="อ. 1" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'อ. 1') echo 'selected="selected"';?>>อ. 1</option>
                          <option value="อ. 2" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'อ. 2') echo 'selected="selected"';?>>อ. 2</option>
                          <option value="อ. 3" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'อ. 3') echo 'selected="selected"';?>>อ. 3</option>
                          <option value="ป. 1" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ป. 1') echo 'selected="selected"';?>>ป. 1</option>
                          <option value="ป. 2" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ป. 2') echo 'selected="selected"';?>>ป. 2</option>
                          <option value="ป. 3" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ป. 3') echo 'selected="selected"';?>>ป. 3</option>
                          <option value="ป. 4" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ป. 4') echo 'selected="selected"';?>>ป. 4</option>
                          <option value="ป. 5" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ป. 5') echo 'selected="selected"';?>>ป. 5</option>
                          <option value="ป. 6" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ป. 6') echo 'selected="selected"';?>>ป. 6</option>
                          <option value="ม. 1" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ม. 1') echo 'selected="selected"';?>>ม. 1</option>
                          <option value="ม. 2" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ม. 2') echo 'selected="selected"';?>>ม. 2</option>
                          <option value="ม. 3" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ม. 3') echo 'selected="selected"';?>>ม. 3</option>
                          <option value="ม. 4" <?php if($form_status == 'add' || $current_class == 'ม. 4') echo 'selected="selected"';?> >ม. 4</option>
                          <option value="ม. 5" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ม. 5') echo 'selected="selected"';?>>ม. 5</option>
                          <option value="ม. 6" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ม. 6') echo 'selected="selected"';?>>ม. 6</option>
                          <option value="ปี 1" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ปี 1') echo 'selected="selected"';?>>ปี 1</option>
                          <option value="ปี 2" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ปี 2') echo 'selected="selected"';?>>ปี 2</option>
                          <option value="ปี 3" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ปี 3') echo 'selected="selected"';?>>ปี 3</option>
                          <option value="ปี 4" <?php if($form_status != 'add' && isset($current_class) && $current_class == 'ปี 4') echo 'selected="selected"';?>>ปี 4</option>
                          <option value="สูงกว่า ป. ตรี (โปรดระบุ)" <?php if($form_status != 'add' && isset($current_class) && $current_class != 'ต่ำกว่า อ. 1' && $current_class != 'อ. 1' && $current_class != 'อ. 2' && $current_class != 'อ. 3' && $current_class != 'ป. 1' && $current_class != 'ป. 2' && $current_class != 'ป. 3' && $current_class != 'ป. 4' && $current_class != 'ป. 5' && $current_class != 'ป. 6' && $current_class != 'ม. 1' && $current_class != 'ม. 2' && $current_class != 'ม. 3' && $current_class != 'ม. 4' && $current_class != 'ม. 5' && $current_class != 'ม. 6' && $current_class != 'ปี 1' && $current_class != 'ปี 2' && $current_class != 'ปี 3' && $current_class != 'ปี 4') echo 'selected="selected"';?>>สูงกว่า ป. ตรี (โปรดระบุ)</option>
                        </select>
                        <span class="require">
                        <input name="txtCurrentClassOther" id="txtCurrentClassOther" type="text" maxlength="45" <?php if($form_status != 'add' && isset($current_class) && $current_class != 'ต่ำกว่า อ. 1' && $current_class != 'อ. 1' && $current_class != 'อ. 2' && $current_class != 'อ. 3' && $current_class != 'ป. 1' && $current_class != 'ป. 2' && $current_class != 'ป. 3' && $current_class != 'ป. 4' && $current_class != 'ป. 5' && $current_class != 'ป. 6' && $current_class != 'ม. 1' && $current_class != 'ม. 2' && $current_class != 'ม. 3' && $current_class != 'ม. 4' && $current_class != 'ม. 5' && $current_class != 'ม. 6' && $current_class != 'ปี 1' && $current_class != 'ปี 2' && $current_class != 'ปี 3' && $current_class != 'ปี 4') echo 'value="'.$current_class.'"'; else echo 'style="visibility:hidden;"'; ?>/>
                        </span></td>
                  </tr>
                  <tr>
                    <td align="right"><label>โรงเรียน</label></td>
                    <td align="left"><input name="txtSchool" id="txtSchool" type="text"  maxlength="45" <?php if($form_status != 'add' && isset($school)) echo 'value="'.$school.'"';?>/>  
                     <label>แผนการเรียน(ถ้ามี)</label> <input name="txtPlan" id="txtPlan" type="text"  maxlength="45" <?php if($form_status != 'add' && isset($plan_edu)) echo 'value="'.$plan_edu.'"';?>/></td>
                  </tr>
                  <tr>
                    <td align="right"><label>หลักสูตร</label></td>
                    <td align="left">
                      <select name="txtCourse" id="txtCourse" onchange="handleCouse(this);">
                        <option value="ภาษาไทย" <?php if($form_status == 'add' || $course_type == 'ภาษาไทย') echo 'selected="selected"';?>>ภาษาไทย</option>
                        <option value="นานาชาติ" <?php if($form_status != 'add' && isset($course_type) && $course_type == 'นานาชาติ') echo 'selected="selected"';?>>นานาชาติ</option>
                        <option value="อื่นๆ (โปรดระบุ)" <?php if($form_status != 'add' && isset($course_type) && $course_type != 'ภาษาไทย' &&  $course_type != 'นานาชาติ') echo 'selected="selected"';?>>อื่นๆ (โปรดระบุ)</option>
                    </select>
                      <span class="require">
                      <input name="txtCourseOther" id="txtCourseOther" type="text" maxlength="45" <?php if($form_status != 'add' && isset($course_type) && $course_type != 'ภาษาไทย' &&  $course_type != 'นานาชาติ') echo 'value="'.$course_type.'"'; else echo 'style="visibility:hidden;"'; ?> />
                    </span> </td>
                  </tr>
                  <tr>
                    <td align="right"><label>เลขที่บัตรประชาชน</label>                      </td>
                    <td align="left"><input name="txtCitizenId" id="txtCitizenId" type="text" maxlength="30" <?php if($form_status != 'add' && isset($citizen_id)) echo 'value="'.$citizen_id.'"';?> /></td>
                  </tr>
                  <tr>
                    <td align="right" ><label>รูปถ่าย</label></td>
                    <td align="left"><div id='uploader'><input name="txtStudentImg" id="txtStudentImg" type="file" style="width:500px;" onchange="checkImageExt(this);" /></div></td>
                  </tr>
                 
                  <tr>
                    <td align="right"><label>โรงเรียนที่สังกัด</label></td>
                    <td align="left">
                    	<?php
							foreach ($schoolList as $row) {
							    echo ' <input type="checkbox" name="chkSchool[]" value="'.$row->school_id .'"';
							    if(isset($schoolListCheck) && in_array($row->school_id, $schoolListCheck)) {
							    	echo ' checked="checked" ';
							    } 
							    echo ' /> '.$row->school_name.' ';
							}
                        ?>
                      </td>
                  </tr>
                  <tr>
                    <td align="right"><label>หมายเหตุ</label></td>
                    <td align="left"><input name="txtComment" id="txtComment" type="text" size="100" maxlength="250" <?php if($form_status != 'add' && isset($comment)) echo 'value="'.$comment.'"';?> /></td>
                  </tr>
                   <tr>
                    <td align="right" valign="top"><label>Black list ?</label></td>
                    <td align="left">
                      <input type="checkbox" name="chkBlackList" id="chkBlackList" value="Y" <?php if($form_status != 'add' && isset($isBacklist) && $isBacklist == 'Y') echo ' checked="checked"';?>/>
                      Black list
                      <br />
                     <input name="txtBlackList" id="txtBlackList" type="text" size="100" maxlength="250" <?php if($form_status != 'add' && isset($blackList_comment)) echo ' value="'.$blackList_comment.'"';?> /></td>
                  </tr>
                   <tr style="height: 10px;">
                     <td align="right"></td>
                     <td align="left"></td>
                   </tr>
          </table>
          <?php } else { echo '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>'; }?>
          </fieldset>
		</td>
	</tr>
    <tr style="height:10px;">
    	<td></td>
    </tr>
    <tr >
    <?php if($form_status != 'notPermit') {?>
        <td align="center"><input name="" type="submit"  value="บันทึกข้อมูล"/>
        <br /></td>
       <?php } ?>
    </tr>
    <tr style="height:10px;">
    	<td></td>
    </tr>
</table>
<?=form_close();?> 
</div>